unit u_sound;

interface
{$O-}
uses
  system.Windows.forms,
  Microsoft.DirectX,
  Microsoft.DirectX.DirectSound,
 Microsoft.DirectX.AudioVideoPlayback;

type

c_Sound = Class
  sound_device : Device;
  buffer : SecondaryBuffer;
  BufferPrinc : Buffer;
  desc : BufferDescription;
  mp3 : Audio;
  procedure createdevice (formctrl : control);
  procedure playsound (son : string);
  procedure playsoundLoop (son : string);
  procedure playmp3 (son : string);
  procedure stopsound(formctrl : control);
end;

implementation
procedure c_Sound.createdevice (formctrl : control);
begin
  desc := BufferDescription.Create();
  desc.GlobalFocus := true;
  desc.ControlVolume := true;
  sound_device := device.Create();
  sound_device.SetCooperativeLevel(formctrl,CooperativeLevel.Priority);
end;

procedure c_Sound.playsound (son : string);
  begin
    Buffer := SecondaryBuffer.create('./Sound/'+son, sound_device);
    Buffer.Play(0, BufferPlayFlags.Default);
  end;

procedure c_Sound.playsoundLoop (son : string);
  begin
    BufferPrinc := Secondarybuffer.Create('./Sound/'+son, desc, sound_device);
    BufferPrinc.Play(0, BufferPlayFlags.Looping);
  end;

procedure c_Sound.playmp3(son: string);
begin
  mp3 := Audio.Create('./Sound/'+son);
  mp3.Play();
end;

procedure c_Sound.stopsound(formctrl : control);
  begin
    buffer.Stop;
    mp3.Stop;
  end;


end.
